<template>
	<view class="chart-wrapper">
		<!-- 自定义标题区域 -->
		<view class="chart-title">
			<text class="title-text">业绩构成分析</text>
		</view>

		<!-- 饼状图组件 -->
		<qiun-data-charts type="ring" :opts="opts" :chartData="chartData" />
	</view>
</template>

<script>
	import {
		selectOpenDoorPerformance
	} from '@/common/api/statistics.js'
	import {
		convertObjToArray
	} from '@/utils/util.js'
	export default {
		data() {
			return {
				chartData: {},
				//您可以通过修改 config-ucharts.js 文件中下标为 ['ring'] 的节点来配置全局默认参数，如都是默认参数，此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式，达到页面简洁的需求。
				opts: {
					rotate: false,
					rotateLock: false,
					padding: [5, 5, 5, 5],
					dataLabel: true,
					enableScroll: false,
					legend: {
						show: true,
						position: "right",
						lineHeight: 25
					},
					title: {
						name: "",
						fontSize: 15,
						color: "#666666"
					},
					subtitle: {
						name: "",
						fontSize: 25,
						color: "#7cb5ec"
					},
					extra: {
						ring: {
							ringWidth: 60,
							activeOpacity: 0.5,
							activeRadius: 10,
							offsetAngle: 0,
							labelWidth: 15,
							border: true,
							borderWidth: 3,
							borderColor: "#FFFFFF"
						}
					}
				}
			};
		},
		created() {
			this.getData();
		},
		methods: {
			async getData() {
				try {
					let res = await selectOpenDoorPerformance()
					this.getServerData(res.data);
				} catch (error) {
					//TODO handle the exception
				}
			},
			getServerData(data) {
				let res = {
					series: [{
						data: convertObjToArray(data)
					}]
				};
				this.chartData = JSON.parse(JSON.stringify(res));
			},
		}
	};
</script>
<style scoped>
	.chart-wrapper {
		padding: 30rpx;
		background-color: #fff;
		/* border-radius: 16rpx; */
		margin-bottom: 24rpx;
	}

	/* 自定义标题样式 */
	.chart-title {
		display: flex;
		justify-content: space-between;
		/* 标题左对齐，省略号右对齐 */
		align-items: center;
		padding: 0 20rpx 20rpx;
		/* 底部留出距离 */
		/* border-bottom: 1px solid #f5f5f5; */
		/* 底部分隔线 */
		/* margin-bottom: 20rpx; */
	}

	.title-text {
		font-size: 30rpx;
		font-weight: bold;
		color: #333;
		/* 标题深色 */
	}

	.more-icon {
		font-size: 36rpx;
		color: #999;
		/* 省略号浅色 */
		padding: 10rpx;
	}
</style>